<?php
require_once("setup.php");
require_once(CLASS_PATH.'translation.class.php');

$translations = Translation::getTranslations(array(
	'withTerm' => true,
	'orderby' => 'terms.id_term'
));

$json = array();
$json_last_entry = array();
$last_t = null;
foreach ($translations as $t) {
	
	$title = $t->title;
	$infotranslation = array(
		'translation' => $t->translation
	);
	
	if (!empty($title)) {
		$infotranslation['subtranslation'] = $title;
	}
	
	if (!empty($last_t) && $last_t->id_term == $t->id_term) {
		$json_last_entry['translation'][] = $infotranslation;
		$last_t = $t;
		continue;
	}
	
	$title = $t->title;
	
	$json_last_entry = array(
		'word' => $t->getTerm()->kana,
		'translation' => array($infotranslation)
	);
	
	
	$last_t = $t;	
	$json[] = $json_last_entry;
}

header('Content-type: application/json');

echo json_encode(array(
	'lastUpdate' => 'unimplemented',
	'entries' => $json
));
?>